//
//  MainViewController.swift
//  WeiboTest
//
//  Created by 张文文 on 15/5/10.
//  Copyright (c) 2015年 zww. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    @IBOutlet weak var mainTabBar: MainTabBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewControllers()
//        println(self.mainTabBar.composedButton)
        self.mainTabBar.composedButton.addTarget(self, action:"clickCompose", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    /// 撰写按钮监听方法 - 因为 OC 的消息机制，所以按钮监听方法不能够使用 private
    func clickCompose(){
        println("\(__FUNCTION__)")
        
    }
    ///添加所有的子视图控制器
    private func addChildViewControllers() {
     
        //设置文字的渲染颜色
        self.tabBar.tintColor = UIColor.orangeColor()
        
//        addChildViewController("Home", title: "首页", imageName: "tabbar_home")

        addChildViewController("Home", "首页", "tabbar_home")
        addChildViewController("Message", "消息", "tabbar_message_center")
        addChildViewController("Discover", "发现", "tabbar_discover")
        addChildViewController("Profile", "我", "tabbar_profile")
        
    }
    ///swift中允许函数的重载  方法名相同，参数个数及类型不同    "_" 忽略
    private func addChildViewController(sbName: String, _ title :String, _ imageName:String) {
        //拿到Home
        let sb = UIStoryboard(name: sbName, bundle: nil)
        //sb的根控制器是nav
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
        nav.title = title
        //栈顶控制器的title
        nav.topViewController.title = title
        //设置导航栏的图标
        nav.tabBarItem.image = UIImage(named: imageName)
        //设置选中后的图片
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        //添加NAV 
        addChildViewController(nav)

    }

    
}
